package com.leoman.utils;

import org.codehaus.jackson.map.ObjectMapper;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * dota2Api
 * Created by 涂奕恒 on 2017/1/11 0011.
 */
public class Dota2Api {

    private static String apiKey = "5022BB2D870DD0AE77DB4A4A175A3ACA";

    public static void main(String[] args) {
        getHeros();
    }

    public static void getHeros() {
        try {
            /*Dota2APIWrapper api = new Dota2APIWrapper(apiKey);*/
            String query = "https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/?key=" + apiKey + "&language=en_cn";
            Map map = doGet(query);
            Map result = (Map) map.get("result");
            List heroes = (List) result.get("heroes");
            Iterator var6 = heroes.iterator();

            while (var6.hasNext()) {
                Map hero = (Map) var6.next();
                System.out.println("**************** hero info ****************");
                System.out.println("id = " + hero.get("id"));
                System.out.println("name = " + hero.get("name"));
                System.out.println("chineseName = " + getHeroNameByKey(hero.get("name").toString()));
                System.out.println("");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static Map doGet(String query) throws IOException {
        URL url = new URL(query);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        StringBuffer response = new StringBuffer();

        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }

        in.close();
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(response.toString(), Map.class);
    }

    public static String getHeroNameByKey(String key) {
        Map<String, String> map = new HashMap<>();
        map.put("npc_dota_hero_abaddon", "亚巴顿-死亡骑士");
        map.put("npc_dota_hero_abyssal_underlord", "孽主");
        map.put("npc_dota_hero_alchemist", "炼金术师");
        map.put("npc_dota_hero_ancient_apparition", "极寒幽魂");
        map.put("npc_dota_hero_antimage", "敌法师");
        map.put("npc_dota_hero_arc_warden", "天穹守望者");
        map.put("npc_dota_hero_axe", "斧王");
        map.put("npc_dota_hero_bane", "贝恩-祸乱之源");
        map.put("npc_dota_hero_batrider", "蝙蝠骑士");
        map.put("npc_dota_hero_beastmaster", "兽王");
        map.put("npc_dota_hero_bloodseeker", "血魔");
        map.put("npc_dota_hero_bounty_hunter", "赏金猎人");
        map.put("npc_dota_hero_brewmaster", "酒仙");
        map.put("npc_dota_hero_bristleback", "刚背兽");
        map.put("npc_dota_hero_broodmother", "育母蜘蛛");
        map.put("npc_dota_hero_centaur", "半人马战行者");
        map.put("npc_dota_hero_chaos_knight", "混沌骑士");
        map.put("npc_dota_hero_chen", "陈");
        map.put("npc_dota_hero_clinkz", "克林克兹-骨弓");
        map.put("npc_dota_hero_crystal_maiden", "水晶室女");
        map.put("npc_dota_hero_dark_seer", "黑暗贤者");
        map.put("npc_dota_hero_dazzle", "戴泽-暗影牧师");
        map.put("npc_dota_hero_death_prophet", "死亡先知");
        map.put("npc_dota_hero_disruptor", "干扰者");
        map.put("npc_dota_hero_doom_bringer", "末日使者");
        map.put("npc_dota_hero_dragon_knight", "龙骑士");
        map.put("npc_dota_hero_drow_ranger", "卓尔游侠");
        map.put("npc_dota_hero_earthshaker", "撼地者");
        map.put("npc_dota_hero_earth_spirit", "大地之灵");
        map.put("npc_dota_hero_elder_titan", "上古巨神");
        map.put("npc_dota_hero_ember_spirit", "灰烬之灵");
        map.put("npc_dota_hero_enchantress", "魅惑魔女");
        map.put("npc_dota_hero_enigma", "谜团");
        map.put("npc_dota_hero_faceless_void", "虚空假面");
        map.put("npc_dota_hero_furion", "先知");
        map.put("npc_dota_hero_gyrocopter", "矮人直升机");
        map.put("npc_dota_hero_huskar", "哈斯卡-神灵武士");
        map.put("npc_dota_hero_invoker", "祈求者");
        map.put("npc_dota_hero_jakiro", "杰奇洛-双头龙");
        map.put("npc_dota_hero_juggernaut", "主宰");
        map.put("npc_dota_hero_keeper_of_the_light", "光之守卫");
        map.put("npc_dota_hero_kunkka", "昆卡-海军上将");
        map.put("npc_dota_hero_legion_commander", "军团指挥官");
        map.put("npc_dota_hero_leshrac", "拉希克-受折磨的灵魂");
        map.put("npc_dota_hero_lich", "巫妖");
        map.put("npc_dota_hero_life_stealer", "噬魂鬼");
        map.put("npc_dota_hero_lina", "丽娜");
        map.put("npc_dota_hero_lion", "莱恩-恶魔巫师");
        map.put("npc_dota_hero_lone_druid", "德鲁伊");
        map.put("npc_dota_hero_luna", "露娜-月之骑士");
        map.put("npc_dota_hero_lycan", "狼人");
        map.put("npc_dota_hero_magnataur", "马格纳斯-半人猛犸");
        map.put("npc_dota_hero_medusa", "美杜莎-蛇发女妖");
        map.put("npc_dota_hero_meepo", "米波-地卜师");
        map.put("npc_dota_hero_mirana", "米娜拉-月之女祭司");
        map.put("npc_dota_hero_morphling", "变体精灵");
        map.put("npc_dota_hero_monkey_king", "齐天大圣");
        map.put("npc_dota_hero_naga_siren", "娜迦海妖");
        map.put("npc_dota_hero_necrolyte", "死灵法师");
        map.put("npc_dota_hero_nevermore", "奈文摩尔-影魔");
        map.put("npc_dota_hero_night_stalker", "暗夜魔王");
        map.put("npc_dota_hero_nyx_assassin", "司夜刺客");
        map.put("npc_dota_hero_obsidian_destroyer", "殁境神蚀者");
        map.put("npc_dota_hero_ogre_magi", "食人魔魔法师");
        map.put("npc_dota_hero_omniknight", "全能骑士");
        map.put("npc_dota_hero_oracle", "神谕者");
        map.put("npc_dota_hero_phantom_assassin", "幻影刺客");
        map.put("npc_dota_hero_phantom_lancer", "幻影长矛手");
        map.put("npc_dota_hero_phoenix", "凤凰");
        map.put("npc_dota_hero_puck", "帕克-仙女龙");
        map.put("npc_dota_hero_pudge", "帕吉-屠夫");
        map.put("npc_dota_hero_pugna", "帕格纳-遗忘法师");
        map.put("npc_dota_hero_queenofpain", "痛苦女王");
        map.put("npc_dota_hero_rattletrap", "发条技师");
        map.put("npc_dota_hero_razor", "剃刀-闪电幽魂");
        map.put("npc_dota_hero_riki", "力丸-隐形刺客");
        map.put("npc_dota_hero_rubick", "拉比克-大魔导师");
        map.put("npc_dota_hero_sand_king", "沙王");
        map.put("npc_dota_hero_shadow_demon", "暗影恶魔");
        map.put("npc_dota_hero_shadow_shaman", "暗影萨满");
        map.put("npc_dota_hero_shredder", "伐木机");
        map.put("npc_dota_hero_silencer", "沉默术士");
        map.put("npc_dota_hero_skeleton_king", "骷髅王");
        map.put("npc_dota_hero_skywrath_mage", "天怒法师");
        map.put("npc_dota_hero_slardar", "斯拉达-鱼人守卫");
        map.put("npc_dota_hero_slark", "斯拉克-鱼人夜行者");
        map.put("npc_dota_hero_sniper", "狙击手");
        map.put("npc_dota_hero_spectre", "幽鬼");
        map.put("npc_dota_hero_spirit_breaker", "裂魂人");
        map.put("npc_dota_hero_storm_spirit", "风暴之灵");
        map.put("npc_dota_hero_sven", "斯温-流浪剑客");
        map.put("npc_dota_hero_techies", "工程师");
        map.put("npc_dota_hero_templar_assassin", "圣堂刺客");
        map.put("npc_dota_hero_terrorblade", "灵魂守卫");
        map.put("npc_dota_hero_tidehunter", "潮汐猎人");
        map.put("npc_dota_hero_tinker", "地精修补匠");
        map.put("npc_dota_hero_tiny", "小小");
        map.put("npc_dota_hero_treant", "树精卫士");
        map.put("npc_dota_hero_troll_warlord", "巨魔战将");
        map.put("npc_dota_hero_tusk", "巨牙海民");
        map.put("npc_dota_hero_undying", "不朽尸王");
        map.put("npc_dota_hero_ursa", "乌尔萨-熊战士");
        map.put("npc_dota_hero_vengefulspirit", "复仇之魂");
        map.put("npc_dota_hero_venomancer", "剧毒术士");
        map.put("npc_dota_hero_viper", "冥界亚龙");
        map.put("npc_dota_hero_visage", "维萨吉-死灵飞龙");
        map.put("npc_dota_hero_warlock", "术士");
        map.put("npc_dota_hero_weaver", "编织者");
        map.put("npc_dota_hero_windrunner", "风行者");
        map.put("npc_dota_hero_winter_wyvern", "寒冬飞龙");
        map.put("npc_dota_hero_wisp", "神灵守卫");
        map.put("npc_dota_hero_witch_doctor", "巫医");
        map.put("npc_dota_hero_zuus", "宙斯-众神之王");

        return map.get(key);
    }
}
